package Database;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import Model.Forms;

public class FormsDB {
	
	public static ArrayList <Forms> GetFormNames()
	{
		Connection con = DBConnection.connect(true);
		PreparedStatement stmt = null;
		ResultSet rs = null;
		String select = "SELECT * FROM qmsdb.forms ORDER BY FormName";

		ArrayList<Forms> FnameArry = new ArrayList<Forms>();
		Forms form = null;

		try
		{
			stmt = con.prepareStatement(select);
			rs = stmt.executeQuery();
			while (rs.next())
			{
				form = new Forms();
				form.setFname(rs.getString("FormName"));
				form.setId(rs.getInt("idForms"));

				FnameArry.add(form);
			}
		}
		catch (Exception e)
		{
			e.printStackTrace();
			form = null;
		}
		finally
		{
			try
			{
				if (rs != null)
					rs.close();
				if (stmt != null)
					stmt.close();
				if (con != null)
					con.close();
			}
			catch (SQLException e)
			{
			}
		}

		return FnameArry;
	}
	
	
}
